// 语言包
const languages = {
    zh: {
        // 导航
        nav_home: "首页",
        nav_about: "关于我",
        nav_projects: "项目",
        nav_contact: "联系我",
        
        // 网站标题
        site_title: "个人作品集",
        logo_text: "我的作品集",
        
        // 首页区域
        hero_title: "欢迎来到我的作品集",
        hero_subtitle: "我是前端开发者，专注于创建美观且功能强大的网站",
        hero_button: "查看我的作品",
        
        // 关于我区域
        about_title: "关于我",
        about_description1: "我是一名Python Developer，擅长消息中间件、实时数据处理、高可用架构设计。",
        about_description2: "我喜欢Rust编程语言，同时也是幸运星、孤独摇滚、摇曳露营的粉丝。",
        skills_title: "技能标签",
        achievements_title: "个人成就",
        achievement1: "清华大学优秀毕业生",
        achievement2: "微软MVP",
        achievement3: "华为开发者认证",
        timeline_title: "专业经历",
        timeline_1_year: "2010-2014",
        timeline_1_title: "清华大学",
        timeline_1_desc: "本科",
        timeline_2_year: "2014-2016",
        timeline_2_title: "斯坦福大学",
        timeline_2_desc: "硕士",
        timeline_3_year: "2017-2020",
        timeline_3_title: "Google",
        timeline_3_desc: "软件工程师",
        timeline_4_year: "2021-2023",
        timeline_4_title: "OpenAI",
        timeline_4_desc: "软件工程师",
        
        // 项目区域
        projects_title: "我的项目",
        project_1_title: "项目名称1",
        project_1_desc: "项目描述1",
        project_2_title: "项目名称2",
        project_2_desc: "项目描述2",
        project_3_title: "项目名称3",
        project_3_desc: "项目描述3",
        
        // 联系区域
        contact_title: "📧 联系我",
        contact_name_placeholder: "您的姓名",
        contact_email_placeholder: "您的邮箱",
        contact_message_placeholder: "您的消息",
        contact_submit: "发送消息",
        social_title: "关注我",
        social_website: "🌐 个人网页",
        social_email: "✉️ 邮箱",
        
        // 页脚
        footer_text: "&copy; 2023 我的作品集. 保留所有权利.",
        
        // 表单验证
        form_success: "感谢您的消息！我会尽快回复您。",
        form_error: "请填写所有必填字段。"
    },
    en: {
        // 导航
        nav_home: "Home",
        nav_about: "About",
        nav_projects: "Projects",
        nav_contact: "Contact",
        
        // 网站标题
        site_title: "Portfolio",
        logo_text: "My Portfolio",
        
        // 首页区域
        hero_title: "Welcome to My Portfolio",
        hero_subtitle: "I'm a frontend developer focused on creating beautiful and powerful websites",
        hero_button: "View My Work",
        
        // 关于我区域
        about_title: "About Me",
        about_description1: "I'm a Python Developer specializing in message middleware, real-time data processing, and high-availability architecture design.",
        about_description2: "I love the Rust programming language, and I'm also a fan of Lucky Star, Hitori Bocchi, and Laid-Back Camp.",
        skills_title: "Skills",
        achievements_title: "Achievements",
        achievement1: "Tsinghua University Outstanding Graduate",
        achievement2: "Microsoft MVP",
        achievement3: "Huawei Developer Certification",
        timeline_title: "Professional Experience",
        timeline_1_year: "2010-2014",
        timeline_1_title: "Tsinghua University",
        timeline_1_desc: "Bachelor's Degree",
        timeline_2_year: "2014-2016",
        timeline_2_title: "Stanford University",
        timeline_2_desc: "Master's Degree",
        timeline_3_year: "2017-2020",
        timeline_3_title: "Google",
        timeline_3_desc: "Software Engineer",
        timeline_4_year: "2021-2023",
        timeline_4_title: "OpenAI",
        timeline_4_desc: "Software Engineer",
        
        // 项目区域
        projects_title: "My Projects",
        project_1_title: "Project 1",
        project_1_desc: "Project Description 1",
        project_2_title: "Project 2",
        project_2_desc: "Project Description 2",
        project_3_title: "Project 3",
        project_3_desc: "Project Description 3",
        
        // 联系区域
        contact_title: "📧 Contact Me",
        contact_name_placeholder: "Your Name",
        contact_email_placeholder: "Your Email",
        contact_message_placeholder: "Your Message",
        contact_submit: "Send Message",
        social_title: "Follow Me",
        social_website: "🌐 Website",
        social_email: "✉️ Email",
        
        // 页脚
        footer_text: "&copy; 2023 My Portfolio. All rights reserved.",
        
        // 表单验证
        form_success: "Thank you for your message! I'll get back to you soon.",
        form_error: "Please fill in all required fields."
    }
};

// 当前语言，默认为中文
let currentLanguage = 'zh';

// 获取翻译文本的函数
function getText(key) {
    return languages[currentLanguage][key] || languages['zh'][key] || key;
}

// 切换语言的函数
function switchLanguage(lang) {
    currentLanguage = lang;
    updatePageLanguage();
    // 保存用户选择的语言到本地存储
    localStorage.setItem('preferredLanguage', lang);
}

// 更新页面语言的函数
function updatePageLanguage() {
    // 更新导航链接
    document.querySelector('.nav-links li:nth-child(1) a').textContent = getText('nav_home');
    document.querySelector('.nav-links li:nth-child(2) a').textContent = getText('nav_about');
    document.querySelector('.nav-links li:nth-child(3) a').textContent = getText('nav_projects');
    document.querySelector('.nav-links li:nth-child(4) a').textContent = getText('nav_contact');
    
    // 更新logo文本
    document.querySelector('.logo').textContent = getText('logo_text');
    
    // 更新页面标题
    document.title = getText('site_title');
    
    // 更新首页区域
    document.querySelector('.hero h1').textContent = getText('hero_title');
    document.querySelector('.hero p').textContent = getText('hero_subtitle');
    document.querySelector('.cta-button').textContent = getText('hero_button');
    
    // 更新关于我区域
    document.querySelector('#about h2').textContent = getText('about_title');
    document.querySelectorAll('.profile-text p')[0].textContent = getText('about_description1');
    document.querySelectorAll('.profile-text p')[1].textContent = getText('about_description2');
    document.querySelector('.skills h3').textContent = getText('skills_title');
    document.querySelector('.achievements h3').textContent = getText('achievements_title');
    document.querySelectorAll('.achievements li')[0].textContent = getText('achievement1');
    document.querySelectorAll('.achievements li')[1].textContent = getText('achievement2');
    document.querySelectorAll('.achievements li')[2].textContent = getText('achievement3');
    document.querySelector('.timeline h3').textContent = getText('timeline_title');
    
    // 更新时间线内容
    document.querySelectorAll('.timeline-year')[0].textContent = getText('timeline_1_year');
    document.querySelectorAll('.timeline-detail h4')[0].textContent = getText('timeline_1_title');
    document.querySelectorAll('.timeline-detail p')[0].textContent = getText('timeline_1_desc');
    
    document.querySelectorAll('.timeline-year')[1].textContent = getText('timeline_2_year');
    document.querySelectorAll('.timeline-detail h4')[1].textContent = getText('timeline_2_title');
    document.querySelectorAll('.timeline-detail p')[1].textContent = getText('timeline_2_desc');
    
    document.querySelectorAll('.timeline-year')[2].textContent = getText('timeline_3_year');
    document.querySelectorAll('.timeline-detail h4')[2].textContent = getText('timeline_3_title');
    document.querySelectorAll('.timeline-detail p')[2].textContent = getText('timeline_3_desc');
    
    document.querySelectorAll('.timeline-year')[3].textContent = getText('timeline_4_year');
    document.querySelectorAll('.timeline-detail h4')[3].textContent = getText('timeline_4_title');
    document.querySelectorAll('.timeline-detail p')[3].textContent = getText('timeline_4_desc');
    
    // 更新项目区域
    document.querySelector('#projects h2').textContent = getText('projects_title');
    document.querySelectorAll('.project-card h3')[0].textContent = getText('project_1_title');
    document.querySelectorAll('.project-card p')[0].textContent = getText('project_1_desc');
    document.querySelectorAll('.project-card h3')[1].textContent = getText('project_2_title');
    document.querySelectorAll('.project-card p')[1].textContent = getText('project_2_desc');
    document.querySelectorAll('.project-card h3')[2].textContent = getText('project_3_title');
    document.querySelectorAll('.project-card p')[2].textContent = getText('project_3_desc');
    
    // 更新联系区域
    document.querySelector('#contact h2').innerHTML = getText('contact_title');
    document.querySelector('#name').placeholder = getText('contact_name_placeholder');
    document.querySelector('#email').placeholder = getText('contact_email_placeholder');
    document.querySelector('#message').placeholder = getText('contact_message_placeholder');
    document.querySelector('#contact-form button').textContent = getText('contact_submit');
    document.querySelector('.social-links h3').textContent = getText('social_title');
    document.querySelectorAll('.social-link')[0].innerHTML = getText('social_website');
    document.querySelectorAll('.social-link')[1].innerHTML = getText('social_email');
    
    // 更新页脚
    document.querySelector('footer p').innerHTML = getText('footer_text');
}